package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmNewsDto;
import com.heima.model.wemedia.dto.WmNewsPageReqDto;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Resource
    WmNewsService wmNewsService;

    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.submit(wmNewsDto);
    }

    @PostMapping("list")
    public ResponseResult getList(WmNewsPageReqDto dto){
        return wmNewsService.getList(dto);
    }

    @GetMapping(path = "/one/{newsId}")
    public ResponseResult one(@PathVariable("newsId") Long newsId) {
        WmNews wmNews = wmNewsService.queryById(newsId);
        return ResponseResult.okResult(wmNews);
    }

    @GetMapping(path = "/del_news/{newsId}")
    public ResponseResult deleteById(@PathVariable("newsId") Long newsId) {
        return wmNewsService.delete(newsId);
    }
}
